﻿using System;
using System.Diagnostics.Contracts;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;

namespace OpenLS.Media
{
    public class SmallImageExtension : MarkupExtension
    {
        private readonly ImageSource _imageSource;

        public SmallImageExtension(string source)
        {
            string actualSource = string.Format("pack://application:,,/OpenLS.Media;component/{0}.png", source);
            try
            {

                _imageSource = new ImageSourceConverter().ConvertFrom(actualSource) as ImageSource;
            }
            catch (Exception)
            {
                // Contract.Assert(false);
                throw;
            }

        }



        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var result = new Image { Stretch = Stretch.Uniform, Source = _imageSource };
            result.Width = 16;
            result.Height = 16;
            return result;

        }
    }
}